require(pacman)
p_load(tidytuesdayR, magick, tidyverse, janitor, trashpanda)Himalayan Mountaineering
Load Libraries
Load Data
tuesdata <- tidytuesdayR::tt_load('2025-01-21')
exped_tidy <- tuesdata$exped_tidy
peaks_tidy <- tuesdata$peaks_tidyData Cleaning
attempts <- exped_tidy |>
left_join(peaks_tidy, by = "PEAKID") |>
clean_names() |>
mutate(across(starts_with("success"), ~as.character(.))) |>
pivot_longer(cols = matches("(route|success)[1-4]"),
names_to = c(".value", "attempt"),
names_pattern = "(route|success)([1-4])") |>
select(expid, pkname, year, season_factor, route, attempt, success, heightm) |>
drop_na(route)Expedition Success Rates
exp_success <- attempts |>
summarise(exp_success = any(as.logical(success)),
.by = c("expid", "season_factor")) |>
summarise(success_rate = mean(exp_success),
n_expeditions = n(),
.by = season_factor)
ggplot(exp_success, aes(season_factor, success_rate)) +
geom_point(size = 3) +
geom_errorbar(aes(
ymin = success_rate - sqrt(success_rate * (1 - success_rate) / n_expeditions),
ymax = success_rate + sqrt(success_rate * (1 - success_rate) / n_expeditions)
), width = 0.08) +
geom_text(data = exp_success,
mapping = aes(x = season_factor,
y = success_rate,
label = paste0("n = ", n_expeditions)),
nudge_x = 0.3, size = 7) +
scale_y_continuous(labels = scales::percent) +
labs(
title = "Himalayan Mountain Expedition Success Rates by Season",
y = "Success rate",
x = "Season"
) +
theme_cole(remove_grid = TRUE, base_size = 25) +
add_caption_cwb(type = "plot", include_data_source = TRUE, data_source = "The Himalayan Database")
Does Size Matter?
attempts <- attempts %>%
mutate(height_bin = cut(
heightm,
breaks = c(0, 7000, 8000, Inf),
labels = c("<7000m", "7000–8000m", "8000m+")
))
height_success <- attempts %>%
summarise(exp_success = any(as.logical(success)),
.by = c("expid", "season_factor", "height_bin")) %>%
summarise(success_rate = mean(exp_success),
n_expeditions = n(),
.by = c("season_factor", "height_bin"))
plot <- ggplot(height_success, aes(season_factor, success_rate, color = height_bin)) +
geom_point(size = 3, position = position_dodge(width = 0.4)) +
geom_errorbar(aes(
ymin = success_rate - sqrt(success_rate * (1 - success_rate) / n_expeditions),
ymax = success_rate + sqrt(success_rate * (1 - success_rate) / n_expeditions)
), width = 0.1, position = position_dodge(width = 0.4)) +
scale_y_continuous(labels = scales::percent) +
scale_colour_viridis_d(end = 0.9) +
labs(
title = "Himalayan Expedition Success by Season & Mountain Height",
y = "Success rate",
x = "Season",
color = "Height bin"
) +
theme_cole(remove_grid = TRUE, base_size = 25) +
add_caption_cwb(type = "plot", include_data_source = TRUE, data_source = "The Himalayan Database")
# Save and display images
current_dir <- dirname(knitr::current_input())
plot_name <- "mountaineering_success.png"
ggsave(plot = plot,
dpi = "screen",
width = 22,
height = 15,
device = ragg::agg_png,
filename = file.path(current_dir, plot_name))
# Read the big plot
img <- image_read(file.path(current_dir, plot_name))
# Force 16:9 aspect ratio with minimal padding
# Target size: 1200x675 px (16:9)
img_card <- image_scale(img, "1200x675") # scale to fit inside 16:9
img_card <- image_extent(
img_card,
geometry = "1200x675",
gravity = "center"
)
# Save as card preview
image_write(img_card, path = file.path(current_dir, "preview.png"))
knitr::include_graphics(
file.path(current_dir, plot_name)
)
References
cite_packages(format = "rmd")Baril C (????). trashpanda: Cole’s Personal Collection of R Functions, Themes, and Palettes. R package version 0.0.1, https://colebaril.github.io/trashpanda/.
Firke S (2024). janitor: Simple Tools for Examining and Cleaning Dirty Data. doi:10.32614/CRAN.package.janitor https://doi.org/10.32614/CRAN.package.janitor, R package version 2.2.1, https://CRAN.R-project.org/package=janitor.
Grolemund G, Wickham H (2011). “Dates and Times Made Easy with lubridate.” Journal of Statistical Software, 40(3), 1-25. https://www.jstatsoft.org/v40/i03/.
Wickham H (2025). forcats: Tools for Working with Categorical Variables (Factors). doi:10.32614/CRAN.package.forcats https://doi.org/10.32614/CRAN.package.forcats, R package version 1.0.1, https://CRAN.R-project.org/package=forcats.
Wickham H (2025). stringr: Simple, Consistent Wrappers for Common String Operations. doi:10.32614/CRAN.package.stringr https://doi.org/10.32614/CRAN.package.stringr, R package version 1.6.0, https://CRAN.R-project.org/package=stringr.
Wickham H, François R, Henry L, Müller K, Vaughan D (2023). dplyr: A Grammar of Data Manipulation. doi:10.32614/CRAN.package.dplyr https://doi.org/10.32614/CRAN.package.dplyr, R package version 1.1.4, https://CRAN.R-project.org/package=dplyr.
Wickham H, Henry L (2026). purrr: Functional Programming Tools. doi:10.32614/CRAN.package.purrr https://doi.org/10.32614/CRAN.package.purrr, R package version 1.2.1, https://CRAN.R-project.org/package=purrr.
Wickham H, Hester J, Bryan J (2025). readr: Read Rectangular Text Data. doi:10.32614/CRAN.package.readr https://doi.org/10.32614/CRAN.package.readr, R package version 2.1.6, https://CRAN.R-project.org/package=readr.
Wickham H, Vaughan D, Girlich M (2025). tidyr: Tidy Messy Data. doi:10.32614/CRAN.package.tidyr https://doi.org/10.32614/CRAN.package.tidyr, R package version 1.3.2, https://CRAN.R-project.org/package=tidyr.
Müller K, Wickham H (2026). tibble: Simple Data Frames. doi:10.32614/CRAN.package.tibble https://doi.org/10.32614/CRAN.package.tibble, R package version 3.3.1, https://CRAN.R-project.org/package=tibble.
Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org.
Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R, Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V, Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). “Welcome to the tidyverse.” Journal of Open Source Software, 4(43), 1686. doi:10.21105/joss.01686 https://doi.org/10.21105/joss.01686.
Ooms J (2025). magick: Advanced Graphics and Image-Processing in R. doi:10.32614/CRAN.package.magick https://doi.org/10.32614/CRAN.package.magick, R package version 2.9.0, https://CRAN.R-project.org/package=magick.
Harmon J, Hughes E (2025). tidytuesdayR: Access the Weekly ‘TidyTuesday’ Project Dataset. doi:10.32614/CRAN.package.tidytuesdayR https://doi.org/10.32614/CRAN.package.tidytuesdayR, R package version 1.2.1, https://CRAN.R-project.org/package=tidytuesdayR.
Rinker TW, Kurkiewicz D (2018). pacman: Package Management for R. version 0.5.0, http://github.com/trinker/pacman.